<% layout('/layouts/default.html', {title: '来文登记表管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-notebook"></i> ${text('来文登记表管理')}
			</div>
			<div class="box-tools pull-left" style="margin-left: 50px;">
				<a href="#" style="color:#FF9900" class="btn btn-default" onclick="selectStatus(0)" id="wait" title="${text('待分发')}"><i class=" "></i> ${text('待分发')}</a>
				<a href="#" class="btn btn-default" onclick="selectStatus(1)" id="ing" title="${text('拟办中')}"><i class=" "></i> ${text('拟办中')}</a>
				<a href="#" style="color:green" class="btn btn-default" onclick="selectStatus(2)" id="ed" title="${text('已分发')}"><i class=" "></i> ${text('已分发')}</a>
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
				<% if(hasPermi('sd:docRecv:edit')){ %>
					<a href="${ctx}/sd/docRecv/form" class="btn btn-default btnTool" title="${text('新增来文登记表')}"><i class="fa fa-plus"></i> ${text('新增')}</a>
				<% } %>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${docRecv}" action="${ctx}/sd/docRecv/listData" method="post" class="form-inline hide"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<div class="form-group">
					<label class="control-label">${text('来文标题')}：</label>
					<div class="control-inline">
						<#form:input path="docTitle" maxlength="500" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('来文文号')}：</label>
					<div class="control-inline">
						<#form:input path="docFullNum" maxlength="100" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('来文自编号')}：</label>
					<div class="control-inline">
						<#form:input path="docSysCode" maxlength="100" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('紧急程度')}：</label>
					<div class="control-inline width-120">
						<#form:select path="docEmergLvl" dictType="recv_doc_emerg_lvl" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('密级')}：</label>
					<div class="control-inline width-120">
						<#form:select path="secLvl" dictType="recv_sec_lvl" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('来文单位')}：</label>

					<div class="control-inline width-120">
						<#form:treeselect id="testUser" title="来文单位选择" path="unitCode"
						url="${ctx}/sd/uppUnit/treeData" class="" allowClear="true"/>
					</div>
				</div>

			<div class="form-group">
				<label class="control-label">${text('来文单位类型')}：</label>
				<div class="control-inline width-120">
					<#form:select id="unitType" path="uppUnit.unitType" dictType="upp_unit_type" blankOption="true" class="form-control"/>
				</div>
			</div>
				<div class="form-group">
					<label class="control-label">${text('来文类型')}：</label>
					<div class="control-inline width-120">
						<#form:select path="docType" dictType="recv_doc_type" blankOption="true" class="form-control"/>
					</div>
				</div>

				<div class="form-group">
					<label class="control-label">${text('文件状态 ')}：</label>
					<div class="control-inline width-120">
						<#form:select path="docStatus" dictType="recv_doc_status" blankOption="true" class="form-control"/>
					</div>
				</div>


				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
				</div>
			</#form:form>
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>
<script>
function selectStatus(status){
	$("#docStatus").val(status).trigger('change');
	page();
}

// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{header:'${text("来文标题")}', name:'docTitle', index:'a.doc_title', width:150, align:"left", frozen:true, formatter: function(val, obj, row, act){
			return '<a href="${ctx}/sd/docRecv/form?id='+row.id+'" class="btnList" data-title="${text("编辑来文登记表")}">'+(val||row.id)+'</a>';
		}},
		{header:'${text("来文文号")}', name:'docFullNum', index:'a.doc_full_num', width:150, align:"left"},
		{header:'${text("来文自编号")}', name:'docSysCode', index:'a.doc_sys_code', width:160, align:"left"},
		{header:'${text("紧急程度")}', name:'docEmergLvl', index:'a.doc_emerg_lvl', width:90, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('recv_doc_emerg_lvl')}, val, '${text("未知")}', true);
		}},
		{header:'${text("密级")}', name:'secLvl', index:'a.sec_lvl', width:60, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('recv_sec_lvl')}, val, '${text("未知")}', true);
		}},
		{header:'${text("文件状态 ")}', name:'docStatus', index:'a.doc_status', width:90, align:"center", formatter: function(val, obj, row, act){
				return	js.getDictLabel(${@DictUtils.getDictListJson('recv_doc_status')}, val, '${text("未知")}', true);

		}},
		{header:'${text("分发份数")}', name:'counts',index:'a.doc_status',width:80, align:"center",formatter: function(val, obj, row, act){
				if(val>0){
					return '<a href="#" data-click-binded="false" title="${text("点击查看分发记录")}" onclick="viewRecord(\''+row.id+'\')" >'+val+'</a>'
				}
				return val;
			}},

		{header:'${text("来文日期")}', name:'docRecvDate', index:'a.doc_recv_date', width:115, align:"center"},
		{header:'${text("来文单位")}', name:'uppUnit.unitName', index:'a.unit_code', width:150, align:"left"},
		{header:'${text("来文类型")}', name:'docType', index:'a.doc_type', width:110, align:"center", formatter: function(val, obj, row, act){
				return js.getDictLabel(${@DictUtils.getDictListJson('recv_doc_type')}, val, '${text("未知")}', true);
			}},
		//{header:'${text("摘要")}', name:'remarks', index:'a.remarks', width:150, align:"left"},
		{header:'${text("操作")}', name:'actions', width:180, sortable:false, title:false, formatter: function(val, obj, row, act){
			var actions = [];
			<% if(hasPermi('sd:docRecv:edit')){ %>
				actions.push('<a href="${ctx}/sd/docRecv/form?id='+row.id+'" class="btnList" title="${text("编辑文件")}"><i class="fa fa-pencil"></i></a>&nbsp;');
				actions.push('<a href="javascript:;" class="btnList" data-click-binded="false" title="${text("操作日志")}" onclick="viewDoc(\''+row.id+'\')"><i class="fa fa-file-text"></i></a>&nbsp;');
					if(row.docStatus == 0){
						actions.push('<a href="${ctx}/sd/docRecv/delete?id='+row.id+'" class="btnList" title="${text("删除文件")}" data-confirm="${text("确认要删除该文件吗？")}"><i class="fa fa-trash-o"></i></a>&nbsp;');
						actions.push('<a href="${ctx}/sd/docRecv/proposed?id='+row.id+'" class="btnList" title="${text("拟办文件")}" data-confirm="${text("确认要拟办该文件吗？")}"><i class="fa fa-edit"></i></a>&nbsp;');
						actions.push('<a href="javascript:;" class="btnList" data-click-binded="false" title="${text("分发文件")}" onclick="deliverDoc(\''+row.id+'\')" ><i class="fa fa-share-square"></i></a>&nbsp;');
					}
					if(row.docStatus == 2){
						actions.push('<a href="${ctx}/sd/docRecv/printCode?id='+row.id+'" class="btnList" title="${text("打印二维码")}" data-confirm="${text("确认要打印该文件二维码吗？")}"><i class="fa icon-printer"></i></a>&nbsp;');
						actions.push('<a href="${ctx}/sd/docRecv/sendMsg?id='+row.id+'" class="btnList" title="${text("发送领文短信")}" data-confirm="${text("确认要发送领文短信吗？")}"><i class="fa fa-send-o (alias)"></i></a>&nbsp;');
					}


				<% } %>
			return actions.join('');
		}}
	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){

	}
});
//分发文件
function deliverDoc(id) {
	js.layer.open({
		type: 2,
		area: [(js.layer.window.outerWidth-200)+'px',(js.layer.window.outerHeight-200)+'px'],
		title: '${text("将文件分发给指定单位")}',
		resize: false,
		scrollbar: true,
		maxmin:true,
		content: '${ctx}/sd/docRecv/toDistribute?id='+id,
		success: function(layero, index){

		},
		btn: ['<i class="fa fa-check"></i> ${text("分发")}',
			'<i class="fa fa-remove"></i> ${text("关闭")}'],
		btn1: function(index, layero){
			var win = layero.iframeWindow();
			var form = {
				inputForm: win.$('#inputForm'),
				btnSubmit: win.$('#btnSubmit'),
			};
            var dataScopeData = [];
            $.each(win.dataScopeTrees, function(key, dataScopeTree){
                var treeNodes = dataScopeTree.getCheckedNodes(true);
                for(var i=0; i<treeNodes.length; i++) {
                    dataScopeData.push({
                        ctrlType: key, ctrlData: treeNodes[i].id
                    });
                }
            });
            win.$("#userDataScopeListJson").val(JSON.stringify(dataScopeData));
            if (win.$('#d1').val() == '') {
                js.layer.msg('领文日期不能为空!', {icon: 5});
                return false;
            }
            if (win.$('#d2').val() == '') {
                js.layer.msg('还文日期不能为空!', {icon: 5});
                return false;
            }
			if (dataScopeData.length == 0) {
					js.layer.msg('分发单位不能为空!', {icon: 5});
					return false;
            }
			//是否打印
			let isPrint = win.$('#isPrint1').parent().hasClass('checked');
			js.ajaxSubmitForm(form.inputForm, function(data){

				if(data.result == Global.TRUE){
					js.showMessage(data.message);
					js.layer.closeAll();
					page();
					if(isPrint){
						$.ajax({
							headers: {
								'Accept': 'application/json',
								'Content-Type': 'application/json'
							},
							contentType: "application/json",
							type: "POST",
							url: "${ctx}/sd/docRecv/printCodeByList",
							data: JSON.stringify(data.data),
							dataType: "json",
							traditional: true,
							success: function (data) {
								js.showMessage(data.message);
							}
						});
					}
					return true;
				}else{
					js.layer.msg(data.message, {icon: 5});
				}

				page();
			}, "json");
			return false;
		}
	});
}

function viewDoc(id) {

	js.layer.open({
		type: 2,
		area: [(js.layer.window.outerWidth-200)+'px',(js.layer.window.outerHeight-200)+'px'],
		title: '${text("查看文件操作日志")}',
		resize: false,
		scrollbar: true,
		maxmin:true,
		content: '${ctx}/sd/docRecv/viewDoc?id='+id,
		success: function(layero, index){

		},
		btn:
			'<i class="fa fa-remove"></i> ${text("关闭")}',

	});
}

function viewRecord(id){
	console.log(id);


	js.layer.open({
		type: 2,
		area: [(js.layer.window.outerWidth-200)+'px',(js.layer.window.outerHeight-200)+'px'],
		title: '${text("查看文件分发记录")}',
		resize: false,
		scrollbar: true,
		maxmin:true,
		content: '${ctx}/sd/docRecv/viewRecord?id='+id,
		success: function(layero, index){

		},
		btn:
				'<i class="fa fa-remove"></i> ${text("关闭")}',

	});
}
</script>